package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.mes.vo.buy.BuyInHouVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.RevokePick;
import com.ruoyi.mes.service.IRevokePickService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 领料返回Controller
 *
 * @author LongAndHao
 * @date 2023-05-16
 */
@RestController
@RequestMapping("/mes/revokepick")
public class RevokePickController extends BaseController
{
    @Autowired
    private IRevokePickService revokePickService;

    /**
     * 查询领料返回列表
     */
    @PreAuthorize("@ss.hasPermi('mes:revokepick:list')")
    @GetMapping("/list")
    public TableDataInfo list(RevokePick revokePick)
    {
        startPage();
        List<RevokePick> list = revokePickService.selectRevokePickList(revokePick);
        return getDataTable(list);
    }

    /**
     * 导出领料返回列表
     */
    @PreAuthorize("@ss.hasPermi('mes:revokepick:export')")
    @Log(title = "领料返回", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RevokePick revokePick)
    {
        List<RevokePick> list = revokePickService.selectRevokePickList(revokePick);
        ExcelUtil<RevokePick> util = new ExcelUtil<RevokePick>(RevokePick.class);
        util.exportExcel(response, list, "领料返回数据");
    }

    /**
     * 获取领料返回详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:revokepick:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(revokePickService.selectRevokePickById(id));
    }

    /**
     * 新增领料返回
     */
    @PreAuthorize("@ss.hasPermi('mes:revokepick:add')")
    @Log(title = "领料返回", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RevokePick revokePick)
    {
        return toAjax(revokePickService.insertRevokePick(revokePick));
    }

    /**
     * 修改领料返回
     */
    @PreAuthorize("@ss.hasPermi('mes:revokepick:edit')")
    @Log(title = "领料返回", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RevokePick revokePick)
    {
        return toAjax(revokePickService.updateRevokePick(revokePick));
    }

    /**
     * 删除领料返回
     */
    @PreAuthorize("@ss.hasPermi('mes:revokepick:remove')")
    @Log(title = "领料返回", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(revokePickService.deleteRevokePickByIds(ids));
    }

    //******************************

    /**
     * 入库
     * @param buyInHouVo
     * @return
     */
    @PostMapping("/inHou")
    public AjaxResult inHou(@RequestBody BuyInHouVo buyInHouVo){
        return revokePickService.inHou(buyInHouVo);
    }

}
